package com.tanhua.server.controller;

import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.UserInfoVo;
import com.tanhua.server.serivce.MessagesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/messages")
public class MessagesController {

    @Autowired
    private MessagesService messagesService;

    /**
     * 添加联系人：
     *   POST   /contacts
     *   参数：
     *      body ： userId
     */
    @PostMapping("/contacts")
    public ResponseEntity contacts(@RequestBody Map map) {
        //获取对方的用户id
        String srt = map.get("userId").toString();
        Long userId = Long.valueOf(srt);
        messagesService.contacts(userId);
        return ResponseEntity.ok(null);
    }

    /**
     * 查询联系人列表
     *    GET   /contacts
     *
     */
    @GetMapping("/contacts")
    public ResponseEntity contacts(@RequestParam(defaultValue = "1") Integer page,
                                   @RequestParam(defaultValue = "10")  Integer pagesize) {
        PageResult vo = messagesService.findFriends(page,pagesize);
        return ResponseEntity.ok(vo);
    }

    /**
     * 根据环信id，查询用户数据
     */
    @GetMapping("/userinfo")
    public ResponseEntity userinfo(String huanxinId) {
        UserInfoVo vo = messagesService.findByhuanxinId(huanxinId);
        return ResponseEntity.ok(vo);
    }
}
